home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / Additions ƒ / Utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-14  |  4.2 KB  |  180 lines  |  [TEXT/MPS ]

  1. /* ------------------------------------------------------------------------------
  2.  
  3.     FILENAME
  4.         Utilities.c
  5.  
  6.     DESCRIPTION
  7.         This file contains the utility routines (e.g. string manipulation routines)
  8.         which are used by the other modules within the Additions printing extension.
  9.         
  10.  
  11.     COPYRIGHT
  12.         Copyright Apple Computer, Inc. 1991 - 1996
  13.         All rights reserved. 
  14.     
  15.     INTERFACE ROUTINES
  16.         GetCopiesFromJob
  17.         MinNum
  18.         StrCopyMax
  19.         StrConcat
  20.         CheckBoxIsOn
  21.         EnableControlOnOff
  22.  
  23.     MODIFICATION HISTORY
  24.         05/15/91            ALA        Initial Implementation
  25.          6/14/96            cn            Updated to support Universal Interfaces 2.1.
  26.  
  27.  
  28. ------------------------------------------------------------------------------- */
  29.  
  30. #include <Types.h>
  31. #include <Quickdraw.h>
  32. #include <Memory.h>
  33. #include <Resources.h>
  34. #include <Dialogs.h>
  35. #include <TextEdit.h>
  36. #include <OSUtils.h>
  37. #include <Packages.h>
  38. #include <ToolUtils.h>
  39. #include <Menus.h>
  40. #include <String.h>
  41. #include <Strings.h>
  42. #include <Printing.h>
  43.  
  44. #include <GXGraphics.h>
  45. #include <GraphicsLibraries.h>
  46. #include <FontLibrary.h>
  47.  
  48. #include <Collections.h>
  49. #include <GXMessages.h>
  50.  
  51. #include    <GXPrinting.h>
  52.  
  53.  
  54. /*==================================== INTERFACE ROUTINES ====================================*/
  55.  
  56.  
  57. /* ===== GetCopiesFromJob =====
  58.  
  59.     Returns the number of copies specified in the job record; 1 if the record cannot be accessed.
  60. */
  61. long GetCopiesFromJob(            //    (out)    Number of copies in the job record
  62.     Collection    jobCollection)    //    (in)    Documents job record
  63. {
  64.     gxCopiesInfo copiesInfo;
  65.     
  66.     copiesInfo.copies = 1;
  67.  
  68.     /* Try and get the print dialog info. */
  69.  
  70.     GetCollectionItem (jobCollection,
  71.                                gxCopiesTag,
  72.                              gxPrintingTagID,
  73.                              nil,
  74.                              &copiesInfo);
  75.  
  76.     return(copiesInfo.copies);
  77. }
  78. /* GetCopiesFromJob */
  79.  
  80.  
  81. /* ===== MinNum =====
  82.  
  83.     Returns the minimum of 'long1' and 'long2'.
  84. */
  85. long MinNum(                // (out)    the minimum of long1 and long2
  86.     long        long1,        // (in)    the first long to consider
  87.     long        long2)        // (in)    the second long to consider
  88. {
  89.     return( ((long1) < (long2)) ? (long1) : (long2) );
  90. }
  91. /* MinNum */
  92.  
  93.  
  94. /* ===== StrCopyMax =====
  95.  
  96.     Copies the contents of 'srcStr' to 'dstStr', but copies no more than maxToCopy characters
  97.     (not including the terminating '\0').
  98.  
  99.     Returns 'dstStr'.
  100. */
  101. char *StrCopyMax(                // (out)    pointer to 'dstStr'
  102.     const char    *srcStr,        // (in)    pointer to the string to copy (C string)
  103.     char            *dstStr,        // (in)    pointer to the string to receive the copy (C string)
  104.     long            maxToCopy)    //    (in)    maximum number of characters to copy
  105. {
  106.     char    *saveStr;
  107.     long    i;
  108.     long    sLen;
  109.  
  110.     saveStr = dstStr;
  111.     sLen = MinNum( strlen(srcStr), maxToCopy );
  112.  
  113.     for ( i = 1; i <= sLen; i++ )
  114.         *(dstStr++) = *(srcStr++);
  115.  
  116.     *dstStr = '\0';
  117.  
  118.     return( saveStr );
  119. }
  120. /* StrCopyMax */
  121.  
  122.  
  123. /* ===== StrConcat =====
  124.  
  125.     Concatenates 'str2' to the end of 'str1' (it is assumed that 'str1'
  126.     can expand by strlen('str2') characters).
  127.  
  128.     Returns 'str1'.
  129. */
  130. char *StrConcat(                // (out)    pointer to 'str1' with 'str2' concatenated
  131.     char            *str1,        // (in)    pointer to the string to concatenate to (C string)
  132.     const char    *str2)        // (in)    pointer to the string to concatenate (C string)
  133. {
  134.     /* copy string2 to the end of string1 (including the trailing '\0') */
  135.     BlockMove( str2, (str1 + strlen(str1)), strlen(str2) + 1 );
  136.  
  137.     return( str1 );
  138. }
  139. /* StrConcat */
  140.  
  141.  
  142. /* ===== CheckBoxIsOn =====
  143.  
  144.     CheckBoxIsOn turns true if a dialog checkbox button is checked; false otherwise.
  145. */
  146. Boolean CheckBoxIsOn(        //    (out)    Returns true if button is checked; false otherwise
  147.     DialogPtr    pDlg,            //    (in)    target dialog
  148.     short            whichItem)    //    (in)    dialog item to be changed
  149. {
  150.     ControlHandle    theChkBox;
  151.     short                itemType;
  152.     Rect                itemRect;
  153.     
  154.     GetDItem(pDlg, whichItem, &itemType, (Handle *) &theChkBox, &itemRect);
  155.     
  156.     return( GetCtlValue(theChkBox) == 1 );
  157. }
  158. /* CheckBoxIsOn */
  159.  
  160.  
  161. /* ===== EnableControlOnOff =====
  162.  
  163.     EnableControlOnOff enables or disables the specified radio button.
  164. */
  165. void EnableControlOnOff(
  166.     DialogPtr    pDlg,            //    (in)    target dialog
  167.     short            whichItem,    //    (in)    dialog item to be changed
  168.     Boolean        enableIt)    //    (in)    T => enable the item; F => disable it
  169. {
  170.     short        itemType;
  171.     Rect        itemRect;
  172.     Handle    hItem;
  173.     
  174.     GetDItem(pDlg, whichItem, &itemType, &hItem, &itemRect);
  175.     HiliteControl((ControlHandle) hItem, (enableIt) ? 0 : 255);
  176. }
  177. /* EnableControlOnOff */
  178.  
  179.  
  180.